<!--
 * @Author: lilin_:）
 * @version: 1.0
 * @Descripttion: 借款明细
 * @Date: 2021-08-29 18:13:41
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-05-07 15:15:33
-->
<template>
	<div class="system-user-container">
		<el-card class="box-card">
			<div>
				<div class="my_btn_lay">
					<div class="my_flex my_btn" @click="searchEvent">
						<div class="my_flex_layout">
							<i class="vxe-icon--search"></i>
							<span>查找</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="resetEvent">
						<div class="my_flex_layout">
							<i class="vxe-icon--refresh"></i>
							<span>重置</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="addDefaultBlank">
						<div class="my_flex_layout">
							<i class="vxe-icon--plus"></i>
							<span>新增</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="deleteTable">
						<div class="my_flex_layout">
							<i class="fa fa-trash-o"></i>
							<span>删除</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="funnelEvent">
						<div class="my_flex_layout">
							<i class="vxe-icon--download"></i>
							<span>导出</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="printTab">
						<div class="my_flex_layout">
							<i class="vxe-icon--print"></i>
							<span>打印</span>
						</div>
					</div>

					<div class="my_flex my_btn ml20" @click="showAmendFun">
						<div class="my_flex_layout">
							<i class="el-icon-edit"></i>
							<span>编辑</span>
						</div>
					</div>
					<div class="my_flex my_btn ml20" @click="editClosedEvent">
						<div class="my_flex_layout">
							<i class="el-icon-folder-add"></i>
							<span>保存</span>
						</div>
					</div>
				</div>

				<vxe-form :data="selectFrom" title-align="left" prevent-submit title-colon>
					<vxe-form-item title="项目" field="" span="4" :item-render="{}">
						<template #default="{ data }">
							<el-select style="width: 100%" clearable filterable v-model="data.contractId" placeholder="请选择项目名称">
								<el-option v-for="item in contractData" :key="item.id" :label="item.contractName" :value="item.id"></el-option>
							</el-select>
						</template>
					</vxe-form-item>

					<vxe-form-item title="备注" field="" span="4" :item-render="{}">
						<template #default="{ data }">
							<el-input style="width: 100%" v-model="data.remarks" placeholder="请输入备注"> </el-input>
						</template>
					</vxe-form-item>

					<vxe-form-item title="借款人" field="contactPerson" span="4" :item-render="{}">
						<template #default="{ data }">
							<el-select style="width: 100%" clearable filterable v-model="data.contactPerson" placeholder="请选择联系人">
								<el-option v-for="item in selectFrom.unitsData" :key="item.id" :label="item.unitName" :value="item.id"> </el-option>
							</el-select>
						</template>
					</vxe-form-item>

					<vxe-form-item title="开始时间" field="time" span="4" :item-render="{}">
						<template #default="{ data }">
							<el-date-picker value-format="YYYY-MM-DD HH:mm:ss" v-model="data.time1" type="date" placeholder="开始时间"> </el-date-picker>
						</template>
					</vxe-form-item>

					<vxe-form-item title="结束时间" field="time" span="4" :item-render="{}">
						<template #default="{ data }">
							<el-date-picker value-format="YYYY-MM-DD HH:mm:ss" v-model="data.time2" type="date" placeholder="结束日期"> </el-date-picker>
						</template>
					</vxe-form-item>

					<vxe-form-item title="是否结清" field="isSettle" span="4" :item-render="{}">
						<template #default="{ data }">
							<el-select style="width: 100%" v-model="data.isSettle" clearable placeholder="是否结清">
								<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
							</el-select>
						</template>
					</vxe-form-item>

					<!-- <vxe-form-item title="开票时间" field="time" span="6" :item-render="{}">
						<template #default="{ data }">
							<el-date-picker
								style="width: 100%"
								v-model="data.time"
								type="datetimerange"
								range-separator="至"
								start-placeholder="开始日期"
								end-placeholder="结束日期"
								value-format="YYYY-MM-DD HH:mm:ss"
							>
							</el-date-picker>
						</template>
					</vxe-form-item> -->

					<!-- <vxe-form-item align="right" span="24" collapse-node>
						<template #default>
							<vxe-button status="primary" content="搜索" @click="searchEvent"></vxe-button>
							<vxe-button content="重置" @click="resetEvent"></vxe-button>
						</template>
					</vxe-form-item> -->
				</vxe-form>
			</div>

			<!-- <vxe-toolbar ref="xToolbar" custom>
				<template #buttons>
					<vxe-button type="text" icon="fa fa-plus" content="新增" @click="addDefaultBlank"></vxe-button>
					<vxe-button type="text" icon="fa fa-trash-o" content="删除" @click="deleteTable"></vxe-button>
				</template>
				<template #tools>
					<vxe-button type="text" icon="vxe-icon--print" class="tool-btn" @click="printTab"></vxe-button>
					<vxe-button type="text" icon="vxe-icon--download" class="tool-btn" @click="funnelEvent"></vxe-button>
				</template>
			</vxe-toolbar> -->
			<!-- @edit-closed="editClosedEvent" -->
			<!-- :merge-footer-items="mergeFooterItems" -->
			<vxe-table
				align="center"
				:scroll-x="{ enabled: false }"
				:scroll-y="{ enabled: false }"
				height="780"
				border
				keep-source
				ref="xTable1"
				:export-config="{}"
				resizable
				show-overflow
				:data="tableData"
				class="mytable-style"
				:row-class-name="rowClassName"
				:edit-rules="validRules"
				:edit-config="{ trigger: 'manual', mode: 'row', icon: 'false' }"
				@checkbox-all="selectAllChangeEvent1"
				@checkbox-change="selectChangeEvent1"
				show-footer
				:footer-method="footerMethod"
				:footer-span-method="footerColspanMethod"
			>
				<vxe-column align="center" type="checkbox" width="60" fixed="left"></vxe-column>
				<vxe-column align="center" type="seq" title="序号" width="60"></vxe-column>

				<vxe-column
					width="105"
					field="time"
					title="时间"
					:edit-render="{ name: '$input', placeholder: '请选择日期', props: { type: 'date', placeholder: '请选择日期' } }"
				></vxe-column>

				<!-- <vxe-column field="borrower" title="借款人" :edit-render="{ name: 'input', attrs: { type: 'text' } }"></vxe-column> -->

				<vxe-column field="borrowerId" title="借款人" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-select clearable filterable v-model="scope.row.borrowerId">
							<el-option v-for="item in selectFrom.unitsData" :key="item.id" :label="item.unitName" :value="item.id"></el-option>
						</el-select>
					</template>
					<template v-slot="{ row }">{{ getSelectLabel(row.borrowerId, selectFrom.unitsData) }}</template>
				</vxe-column>

				<vxe-column field="amount" width="130" title="借款金额" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-input v-model="scope.row.amount" @change="change_interestRate(scope.row)"></el-input>
					</template>
					<template v-slot="{ row }">{{ transitionNumber(row.amount) }}</template>
				</vxe-column>

				<vxe-column field="repayment" title="还款金额" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-input v-model="scope.row.repayment" @change="change_interestRate(scope.row)"></el-input>
					</template>
					<template v-slot="{ row }">{{ transitionNumber(row.repayment) }}</template>
				</vxe-column>

				<!-- <vxe-column
					field="startDate"
					title="起始时间"
					:edit-render="{ name: '$input', placeholder: '请选择日期', props: { type: 'date', placeholder: '请选择日期' } }"
				></vxe-column> -->

				<vxe-column field="startDate" title="起始时间" width="105" :edit-render="{}">
					<template #edit="{ row }">
						<vxe-input @change="change_interestRate(row)" v-model="row.startDate" type="date" placeholder="起始时间" transfer></vxe-input>
					</template>
				</vxe-column>

				<!-- <vxe-column
					field="endDate"
					title="截止时间"
					:edit-render="{ name: '$input', placeholder: '请选择日期', props: { type: 'date', placeholder: '请选择日期' } }"
				></vxe-column> -->

				<vxe-column field="endDate" title="截止时间" width="105" :edit-render="{}">
					<template #edit="{ row }">
						<vxe-input @change="change_interestRate(row)" v-model="row.endDate" type="date" placeholder="截止时间" transfer></vxe-input>
					</template>
				</vxe-column>

				<vxe-column field="interestRate" title="月利率" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-input v-model="scope.row.interestRate" @change="change_interestRate(scope.row)">
							<!-- <template #append>%</template> -->
						</el-input>
					</template>
					<template v-slot="{ row }">{{ row.interestRate }}%</template>
				</vxe-column>

				<vxe-column field="accruedInterest" title="应计利息" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-input v-model="scope.row.accruedInterest"></el-input>
					</template>
					<template v-slot="{ row }">{{ transitionNumber(row.accruedInterest) }}</template>
				</vxe-column>

				<vxe-column field="paidInterest" title="实付利息" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-input v-model="scope.row.paidInterest"></el-input>
					</template>
					<template v-slot="{ row }">{{ transitionNumber(row.paidInterest) }}</template>
				</vxe-column>
				<!-- 				
				<vxe-column field="balance" title="余额" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-input v-model="scope.row.balance"></el-input>
					</template>
					<template v-slot="{ row }">{{ transitionNumber(row.balance) }}</template>
				</vxe-column> -->
				<vxe-column width="80" field="isSettle" title="是否结清" :edit-render="{ name: '$select', options: options }"></vxe-column>

				<vxe-column field="contractId" width="200" title="项目名称" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-select clearable filterable v-model="scope.row.contractId">
							<el-option v-for="item in contractData" :key="item.id" :label="item.contractName" :value="item.id"></el-option>
						</el-select>
					</template>
					<template v-slot="{ row }">{{ getSelectLabelelListTop(row.contractId, contractData) }}</template>
				</vxe-column>

				<vxe-column field="remarks" title="备注" :edit-render="{ type: 'default' }">
					<template v-slot:edit="scope">
						<el-input v-model="scope.row.remarks"></el-input>
					</template>
				</vxe-column>
			</vxe-table>
		</el-card>
	</div>
</template>

<script lang="ts">
import { toRefs, reactive, ref, toRaw, onMounted, nextTick } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import {
	axios_SelList,
	axios_loanselList,
	axios_loanadd,
	axios_loanup,
	axios_loandel,
	axios_selValue_interest,
	axios_selValueBalance,
	axios_selListTop,
} from '/@/api/basicsUrl/index';
import { axios_contactsAdd } from '/@/api/addressBook/index';

import { GenNonDuplicateID } from '/@/utils/formatTime';
import { transitionNumber } from '/@/utils/transitionNumber';
import { VXETable, VxeTableInstance, VxeTablePropTypes } from 'vxe-table';

export default {
	name: 'BorrowMoney',
	setup() {
		const xTable1 = ref({} as VxeTableInstance);
		const xToolbar = ref({} as VxeToolbarInstance);

		// 打印样式
		// 打印样式
		const printStyle = `
            .title {
              text-align: center;
            }
            .my-list-row {
              display: inline-block;
              width: 100%;
            }
            .my-list-col {
              float: left;
              width: 33.33%;
              height: 28px;
              line-height: 28px;
            }
            .my-top,
            .my-bottom {
              font-size: 12px;
            }
            .my-top {
              margin-bottom: 5px;
            }
            .my-bottom {
              margin-top: 30px;
              text-align: right;
            }
            `;

		// 打印顶部内容模板
		const topHtml = `
            <h1 class="title">出货单据</h1>
            <div class="my-top">
              <div class="my-list-row">
                <div class="my-list-col">商品名称： </div>
                <div class="my-list-col">发货单号：X2665847132654</div>
                <div class="my-list-col">发货日期：2020-09-20</div>
              </div>
              <div class="my-list-row">
                <div class="my-list-col">收货姓名： </div>
                <div class="my-list-col">收货地址：火星第七区18号001</div>
                <div class="my-list-col">联系电话：10086</div>
              </div>
            </div>
            `;

		// 打印底部内容模板
		const bottomHtml = `
            <div class="my-bottom">
              <div class="my-list-row">
                <div class="my-list-col"></div>
                <div class="my-list-col">创建人： </div>
                <div class="my-list-col">创建日期：2020-09-20</div>
              </div>
            </div>
            `;

		/**
		 * @Author: lilin_:）
		 * @name: 默认空白数组
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		let defaultBlankData = [
			{
				iswebAdd: true,
				webid: GenNonDuplicateID(),
				time: '',
				borrower: '',
				borrowerId: '', //借款人
				amount: '',
				repayment: '',
				startDate: '',
				endDate: '',
				interestRate: '',
				accruedInterest: '',
				paidInterest: '',
				// 新增字段
				isSettle: '0', //（ 是否结清（1是0否默认
				contractId: '', //合同ID 查询合同单位 合同名称
				contractName: '', //合同名称
				remarks: '', //备注
			},
		];

		const validRules = ref({
			time: [{ required: true, message: '时间必选' }],
			borrowerId: [{ required: true, message: '借款人必填' }],
			interestRate: [{ required: true, message: '月利率必填' }],
			amount: [{ required: true, message: '借款金额必填' }],
		} as VxeTablePropTypes.EditRules);
		const state: any = reactive({
			// mergeFooterItems: [{ row: 0, col: 11, rowspan: 1, colspan: 2 }] as VxeTablePropTypes.MergeFooterItems,
			options: [
				{
					value: '1',
					label: '是',
				},
				{
					value: '0',
					label: '否',
				},
			],

			showSun: {
				v1: 0,
				v2: 0,
				v3: 0,
				v4: 0,
				v5: 0,
			}, // 合计数据
			addList: [], //前端加的数据
			responseData: [], //后端返回的数据
			selectFrom: {
				contractId: '', //项目搜索
				remarks: '', //备注
				time1: '', //时间
				time2: '', //时间
				isSettle: '', // 是否结清（1是0否默认）
				on: 0, //默认是0，1是点击

				contactPerson: '', //联系人
				type: '', //单位类型1供应商2客户3公司员工
				typeArry: [
					{ label: '供应商', value: '1' },
					{ label: '客户', value: '2' },
					{ label: '公司员工', value: '3' },
				], //单位类型1供应商2客户3公司员工
				unitsData: [], //单位搜索的数据和联系人一样
			},
			tableData: [], //表格数据
			selecttableData: [], //选择的数组
			contractData: [], // 合同数据
		});

		const selectAllChangeEvent1: VxeTableEvents.CheckboxAll = ({ checked, records }: any) => {
			console.log(checked ? '所有勾选事件' : '所有取消事件', records);
			state.selecttableData = records;
		};

		const selectChangeEvent1: VxeTableEvents.CheckboxChange = ({ checked, records }: any) => {
			// 重置所有高亮
			state.tableData.forEach((item2: any) => {
				item2.hghligHt = false;
			});
			console.log(checked ? '勾选事件' : '取消事件', records);
			state.selecttableData = records;
			state.selecttableData.forEach((item: any) => {
				if (item.iswebAdd) {
					// 前端的数据
					state.tableData.forEach((item2: any) => {
						if (item.webid == item2.webid) {
							item2.hghligHt = true;
						}
					});
				} else {
					state.tableData.forEach((item2: any) => {
						if (item.id == item2.id) {
							item2.hghligHt = true;
						}
					});
				}
			});
		};

		/**
		 * @Author: lilin_:）
		 * @name: 获取项目名称
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const getProjectName = async () => {
			let resData: any = await axios_SelList({ unitName: '', contactPerson: '', type: '' });
			state.selectFrom.unitsData = resData.obj;
			console.log(toRaw(state.selectFrom.unitsData), '借款人数据');

			// state.tableData = resData.obj;
			// data1 = resData.obj;
		};

		/**
		 * @Author: lilin_:）
		 * @name: 获取借款明细
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const get_TabaDat = () => {
			// let subTme = ''; //判断是否有时间
			// if (state.selectFrom.time) {
			// 	subTme = `${state.selectFrom.time[0]}_${state.selectFrom.time[1]}`;
			// }
			let params = {
				time1: state.selectFrom.time1,
				time2: state.selectFrom.time2,
				on: state.selectFrom.on,
				contractUnitId: state.selectFrom.contactPerson,
				contractId: state.selectFrom.contractId, //项目搜索
				remarks: state.selectFrom.remarks, //备注
				isSettle: state.selectFrom.isSettle, //是否结清
			};
			axios_loanselList(params).then((res: any) => {
				console.log(res, 'state.tableData');

				if (res.code == 200) {
					// 重置数据
					state.addList = [];
					// 添加20条数据
					for (let index = 0; index < 20; index++) {
						state.addList.push(
							defaultBlankData.map((item: any) => {
								return {
									...item,
									...{
										webid: GenNonDuplicateID(),
									},
								};
							})[0]
						);
					}
					state.showSun = res.data;

					state.responseData = res.obj;
					state.selecttableData = [];
					// console.log(state.addList, 'addList');
					state.tableData = [...state.responseData, ...state.addList];
				}
			});
		};

		const searchEvent: VxeFormEvents.Submit = async () => {
			state.selectFrom.on = 1;
			get_TabaDat();
			// VXETable.modal.message({ content: '查询事件', status: 'info' });
		};

		/**
		 * @Author: lilin_:）
		 * @name: 重置搜索表单
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const resetEvent: VxeFormEvents.Reset = async () => {
			state.selectFrom.time1 = ''; //清空时间
			state.selectFrom.tim2 = ''; //清空时间
			state.selectFrom.on = 0;
			state.selectFrom.contactPerson = ''; //单位名称
			state.selectFrom.contractId = ''; //项目搜索
			state.selectFrom.remarks = ''; //备注
			state.selectFrom.isSettle = ''; //是否结清
			await get_TabaDat();
			// VXETable.modal.message({ content: '重置事件', status: 'info' });
		};

		// 获取合同数据新增内容
		let getContractData = async () => {
			let { code, obj } = await axios_selListTop();
			if (code == 200) {
				state.contractData = obj;
			}
			// console.log(code, 'async');
			console.log(obj, 'obj');
		};

		onMounted(() => {
			getProjectName(); //单位名称
			getContractData();
			get_TabaDat();

			// let a = GenNonDuplicateID()
			// console.log(a)
		});

		//实时更新
		const editClosedEvent: VxeTableEvents.EditClosed = ({ row, column }) => {
			// console.log(toRaw(row), '11111');

			if (state.selecttableData.length == 1) {
				let row = state.selecttableData[0];
				if (row.iswebAdd) {
					// 走保存接口
					// console.log(toRaw(row), '我是前端提交');
					axios_loanadd(row).then((res) => {
						// console.log(res, '是否啊添加');
						if (res.code == 200) {
							state.selectFrom.on = 2;
							get_TabaDat();
							VXETable.modal.message({ content: '新增成功!', status: 'success' });
						}
					});
				} else {
					axios_loanup(row).then((res) => {
						if (res.code == 200) {
							state.selectFrom.on = 1;
							get_TabaDat();
							VXETable.modal.message({ content: '编辑成功！', status: 'success' });
						}
					});
					// console.log(toRaw(row), '我是后段提交');
				}
			} else if (state.selecttableData.length == 0) {
				VXETable.modal.message({ content: '您还没有选中行', status: 'warning' });
			} else {
				VXETable.modal.message({ content: '只能选中一行编辑', status: 'warning' });
			}

			// const $table = xTable1.value;
			// const field = column.property;
			// const cellValue = row[field];
			// 判断单元格值是否被修改;
			// if ($table.isUpdateByRow(row, field)) {
			// 	setTimeout(() => {
			// 		VXETable.modal.message({
			// 			content: `局部保存成功！ ${field}=${cellValue}`,
			// 			status: 'success',
			// 		});
			// 		// 局部更新单元格为已保存状态
			// 		$table.reloadRow(row, null, field);
			// 	}, 300);
			// }
		};

		/**
		 * @Author: lilin_:）
		 * @name: 关联表格
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		nextTick(() => {
			// 将表格和工具栏进行关联
			const $table = xTable1.value;
			const $toolbar = xToolbar.value;
			$table.connect($toolbar);
		});

		/**
		 * @Author: lilin_:）
		 * @name: 新增空白行
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const addDefaultBlank = () => {
			let addArry = defaultBlankData.map((item: any) => {
				return {
					...item,
					...{
						webid: GenNonDuplicateID(),
						hghligHt: true,
					},
				};
			});

			let row = addArry[0];
			// let showArry = JSON.parse(JSON.stringify(state.tableData)); // state.responseData.push(row);
			state.addList.unshift(row);
			state.tableData = [...state.responseData, ...state.addList];
			const $table = xTable1.value;
			$table.setActiveRow(row);
			//清空选择的数据
			$table.clearCheckboxRow();
			$table.toggleCheckboxRow(state.addList[0]); //默认选中第一行
			state.selecttableData = [state.addList[0]]; //拿到选择数据

			ElMessage.success({
				message: '新增1行空白栏',
				type: 'success',
			});
			// 计算滚动高度
			let heightpx = state.responseData.length * 40;
			setTimeout(() => {
				document.getElementsByClassName('vxe-table--body-wrapper')[0].scrollTo(0, heightpx);
			}, 100);
		};

		/**
		 * @Author: lilin_:）
		 * @name: 删除数据
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const deleteTable: any = async () => {
			let webAddArry: any = [];
			let reeData: any = [];
			state.selecttableData.forEach((item: any) => {
				if (item.iswebAdd == true) {
					webAddArry.push(item);
				} else {
					reeData.push(item);
				}
			});
			// 判断前端数据是否有值
			let webDelet = () => {
				if (webAddArry.length != 0) {
					// 前端删除
					state.addList = state.addList.filter((item: any) => {
						return !webAddArry.find((_item: any) => _item.webid === item.webid);
					});
					state.selecttableData = [];
					state.tableData = [...state.responseData, ...state.addList];
				}
			};

			let resDelet = async () => {
				if (reeData.length != 0) {
					let { code }: object = await axios_loandel(
						reeData.map((item: any) => {
							return item.id;
						})
					);

					// console.log(code, '11111111');
					if (code == 200) {
						state.selectFrom.on = 1;
						get_TabaDat();
					}
				}
			};
			await resDelet();
			await webDelet();
		};

		/**
		 * @Author: lilin_:）
		 * @name: 高级导出功能
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const funnelEvent = () => {
			const $table = xTable1.value;
			$table.openExport();
		};

		/**
		 * @Author: lilin_:）
		 * @name: 打印表格
		 * @Descripttion:
		 * @param {*}
		 * @return {*}
		 */
		const printTab = () => {
			const $table = xTable1.value;
			$table.print({
				sheetName: '打印发票台账',
				style: printStyle, //自定义样式
				columns: [
					{ field: 'time' },
					{ field: 'borrowerId' },
					{ field: 'amount' },
					{ field: 'repayment' },

					{ field: 'startDate' },
					{ field: 'endDate' },

					{ field: 'interestRate' },

					{ field: 'accruedInterest' },
					{ field: 'paidInterest' },
					{ field: 'isSettle  ' },
					{ field: 'contractId' },
					{ field: 'remarks' },
				],
				beforePrintMethod: ({ content }) => {
					// 拦截打印之前，返回自定义的 html 内容
					// return topHtml + content + bottomHtml;
					return content;
				},
			});
		};

		// 展示内容下拉搜索
		const getSelectLabel = (value, list) => {
			let item = list.find((item) => item.id == value);
			return item ? item.unitName : null;
		};
		// 回显合同单位ID
		const getSelectLabelelListTop = (value, list) => {
			let item = list.find((item) => item.id == value);
			return item ? item.contractName : null;
		};

		// 计算应计利息
		let change_interestRate = (item: any) => {
			// 参数 Date start 开始时间, Date end截止时间, Double interestRate 月利率
			// if (item.startDate != '' && item.interestRate != '' && item.endDate != '') {}
			//   计算应计利息
			axios_selValue_interest({
				interestRate: item.interestRate,
				amount: item.amount,
				repayment: item.repayment,
				start: item.startDate,
				end: item.endDate,
			}).then((res) => {
				if (res.code == 200) {
					if (item.iswebAdd) {
						// 前端的数据
						state.tableData.forEach((item_data, itemdata_index) => {
							if (item_data.webid == item.webid) {
								// console.log(itemdata_index,'itemdata_index')
								item_data.accruedInterest = res.obj;
							}
						});
					} else {
						state.tableData.forEach((item_data, itemdata_index) => {
							if (item_data.id == item.id) {
								// console.log(itemdata_index,'itemdata_index')
								item_data.accruedInterest = res.obj;
							}
						});
					}
				}
			});
		};

		const showAmendFun = () => {
			if (state.selecttableData.length == 1) {
				let row = state.selecttableData[0];
				row.hghligHt = true;
				const $table = xTable1.value;
				$table.setActiveRow(row);
			} else if (state.selecttableData.length == 0) {
				VXETable.modal.message({ content: '您还没有选中行', status: 'warning' });
			} else {
				VXETable.modal.message({ content: '只能选中一行编辑', status: 'warning' });
			}
		};

		// 改变颜色样式
		const rowClassName: VxeTablePropTypes.RowClassName = ({ row }) => {
			// console.log(row, 'rowIndex');
			if (row.hghligHt) {
				return 'row-green';
			}
			return null;
		};

		const footerMethod: VxeTablePropTypes.FooterMethod = ({ columns, data }) => {
			return [
				columns.map((column, columnIndex) => {
					// console.log(columnIndex, '1');
					if (columnIndex === 4) {
						return `${state.showSun.v1}`;
					}
					if (columnIndex === 5) {
						return `${state.showSun.v2}`;
					}
					if (columnIndex === 9) {
						return `${state.showSun.v3}`;
					}
					if (columnIndex == 10) {
						return `${state.showSun.v4}`;
					}
					if (columnIndex == 11) {
						return `未结金额：${state.showSun.v5}`;
					}
					return '';
				}),
			];
		};

		const footerColspanMethod: VxeTablePropTypes.FooterSpanMethod = ({ $rowIndex, _columnIndex }) => {
			if ($rowIndex === 0) {
				if (_columnIndex === 11) {
					return {
						rowspan: 1,
						colspan: 2,
					};
				}
			}
		};

		return {
			footerColspanMethod,
			validRules,
			...toRefs(state),
			showAmendFun,
			editClosedEvent, //实时更新
			xToolbar, //关联表格
			xTable1, //表格
			addDefaultBlank, //新增空白行
			deleteTable, //删除数据
			funnelEvent, //导出数据
			printTab, //打印
			getSelectLabel,
			getSelectLabelelListTop, //合同单位

			change_interestRate, //月利率变动

			selectAllChangeEvent1,
			selectChangeEvent1,
			input: ref(''),
			searchEvent,
			resetEvent,
			transitionNumber,
			rowClassName,
			footerMethod,
		};
	},
};
</script>

<style scoped lang="scss">
.mytable-style ::v-deep .vxe-body--row.row-green {
	background-color: #bbb;
	color: #fff;
}
</style>
